package fr.uparis10.miage.m1p1.global;

import java.util.HashMap;

public class ProjetBudgetStruct {
	/*
	 * we'll only create an object of this type when needed; the HashMaps are
	 * huge objects
	 */
	private HashMap<BudgetReasonChefProjEnum, Double> usageMap;

	/**
	 * Gets the usage for a specific Reason / Activity
	 * 
	 * @param reason
	 * @return
	 */
	public double getUsage(BudgetReasonChefProjEnum reason) {
		if (usageMap == null) {
			return 0;
		}
		Double usage = usageMap.get(reason);
		return usage == null ? 0 : usage;
	}

	/**
	 * Adds some usage for a certain activity
	 * 
	 * @param reason
	 * @param toUse
	 */
	public void addUsage(BudgetReasonChefProjEnum reason, double toUse) {
		if (usageMap == null) {
			/* first call */
			usageMap = new HashMap<BudgetReasonChefProjEnum, Double>();
		}
		Double usage = usageMap.get(reason);
		usage = usage == null ? toUse : usage + toUse;
		/* the new value has to be (re)inserted */
		usageMap.put(reason, usage);
	}

	/**
	 * Set the usage for a certain activity
	 * 
	 * @param reason
	 * @param toUse
	 */
	public void setUsage(BudgetReasonChefProjEnum reason, double toUse) {
		if (usageMap == null) {
			/* first call */
			usageMap = new HashMap<BudgetReasonChefProjEnum, Double>();
		}
		usageMap.put(reason, toUse);
	}
}
